import { Transform } from "class-transformer";
import { IsString, IsInt, IsOptional, ValidateIf, IsArray, ArrayMinSize, ArrayMaxSize, Length } from "class-validator";
import { BaseQueryDto } from "../base.dto";
import { ApiProperty } from "@nestjs/swagger";
import { AuthSignInDto } from "../auth";

export class UserAddDto extends AuthSignInDto {
    @ApiProperty({ type: [Number], description: "角色" })
    @IsArray()
    @ArrayMinSize(1)
    @ArrayMaxSize(3)
    @IsOptional()
    roles?: number[];
}

export class UserRemoveDto {
    @ApiProperty({ description: "数据库id" })
    @IsInt()
    @Transform(({ value }) => parseInt(value))
    id: number;
}

export class UserQueryDto extends BaseQueryDto {}

export class UserUpdateDto extends UserRemoveDto {
    @ApiProperty({ type: [Number], description: "角色" })
    @IsArray()
    @ArrayMinSize(1)
    @ArrayMaxSize(3)
    @IsOptional()
    roles?: number[];

    @ApiProperty({ description: "密码, 6-32" })
    @IsString()
    @Length(6, 32)
    @IsOptional()
    password?: string;
}
